package kotlindemo.com.kotlindemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_json);
        JSONObject jsonObject1 = new JSONObject();

        try {
            jsonObject1.put("name", "Jim");
            jsonObject1.put("age", "20");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JSONObject jsonObject2 = new JSONObject();

        try {
            jsonObject2.put("name", "Tom");
            jsonObject2.put("age", "18");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JSONArray jsonArray = new JSONArray();
        jsonArray.put(jsonObject1);
        jsonArray.put(jsonObject2);
        Log.d("JSON", jsonObject1.toString());
        Log.d("JSON", jsonArray.toString());
    }
}
